<script>
    export default {
        onLaunch: function() {
            this.getSystemInfo()
            this.checkNetwork()
        },
        onShow: function() {
            console.log('App Show')
        },
        onHide: function() {
            console.log('App Hide')
        },
        methods: {
            // 获取系统信息
            getSystemInfo() {
                let info = {
                    isIpx: false
                };
                const _this = this;
                uni.getSystemInfo({
                    success(res) {
                        let deviceModel = 'iPhone X';
                        if (res.model.indexOf(deviceModel) > -1) {
                            info.isIpx = true;
                        }
                        let titleBarHeight = res.model.indexOf('iPhone') !== -1 ? 44 : 48;
                        info.barHeight = titleBarHeight;
                        info.statusBarHeight = res.statusBarHeight;
                        info.platform = res.platform;
                    },
                    fail() {
                        info.barHeight = 68;
                    },
                    complete() {
                        _this.$store.commit('SYSTEMINFO', info)
                    }
                });
            },
            // 检查网络状态
            checkNetwork() {
                uni.getNetworkType({
                    success(res) {
                        const networkType = res.networkType;
                        if (networkType == 'none') {
                            uni.showToast({
                                title: '当前没有网络',
                                icon: 'none',
                                duration: 2000
                            });
                        }
                    }
                });
                uni.onNetworkStatusChange(function(res) {
                    const {
                        isConnected,
                        networkType
                    } = res;
                    if (!isConnected) {
                        uni.showToast({
                            title: '当前没有网络',
                            icon: 'none',
                            duration: 2000
                        });
                    }
                    if (networkType == '2g' || networkType == '3g') {
                        uni.showToast({
                            title: '当前网络环境较差',
                            icon: 'none',
                            duration: 2000
                        });
                    }
                });
            }
        }
    }
</script>

<style>
    /*每个页面公共css */
@import "static/css/public.css";
@import "static/css/icon.css";
</style>
